<?php
/**
 * faq.class.php
 */

class faq{
	var $id;
	var $question;
	var $reply;
	
	/**
	 * add
	 * @param String $question
	 * @param String $reply
	 * @param String $fiType
	 * @return 
	 */
	function add( $question, $reply, $fiType ){
		global $GLOBAL,$COMMON;
		$sql = "INSERT INTO FaqInfo(fi_question, fi_reply, fi_type, fi_datein, fi_opin, fi_ipin) VALUES (?, ?, ?, NOW(), ?, ?)";
		return $COMMON->sql_escape($sql, $question, $reply, $fiType, $GLOBAL["OP_ID"],getenv("REMOTE_ADDR"));
	}

	/**
	 * edit
	 * @param String $question
	 * @param String $reply
	 * @param String $fiType
	 * @param String $fiType
	 * @return 
	 */
	function edit( $question, $reply, $fiType, $fiId ){
		global $COMMON;
		$sql = "UPDATE FaqInfo SET fi_question=?, fi_reply=?,fi_type=? WHERE fi_id=?";
		return $COMMON->sql_escape($sql, $question, $reply, $fiType, $fiId);
	}

	/**
	 * getById 
	 * @param String $reply
	 * @return status
	 */
	function getById( $fiId ){
		global $COMMON;
		$sql = "SELECT * FROM FaqInfo WHERE fi_id=?";
		return $COMMON->sql_escape($sql,$fiId);
	}
	
	/**
	 * del 
	 * @param String $reply
	 * @return status
	 */
	function del( $fiId ){
		global $COMMON, $faqSql;
		$sql = "DELETE FROM FaqInfo WHERE fi_id=?";
		return $COMMON->sql_escape($sql,$fiId);
	}
	
	/**
	 * getSql
	 * @param Array $parr
	 * @return String $sql
	 */
	function getSql($parr = array()){
		$sql = "SELECT * FROM FaqInfo WHERE fi_id<>0";
		if(!empty($parr["fi_type"]))
		$sql .= " AND fi_type='".$parr["fi_type"]."'";
		
		if(!empty($parr["keyword"]))
		$sql .= " AND (fi_question LIKE '%".$parr["keyword"]."%' OR fi_reply LIKE '%".$parr["keyword"]."%')";
		$sql .= " ORDER BY fi_id DESC";
		return $sql;
	}
}

?>